layui.use(['ztree','ax'], function () {
    var $ZTree = layui.ztree;
    var $ax = layui.ax;

    var ZTreeDlg = {
        index: parent.layer.getFrameIndex(window.name)
    };

    $("#saveButton").bind("click", function () {
        var ids = system.zTreeCheckedNodes("zTree");
        var ajax = new $ax(system.contextPath + "/admin/userMenuRoleRelation/setAuthority/" + system.getUrlParam("id"), function (res) {
            if(res.status){
                system.success("成功!");
                parent.layer.close(ZTreeDlg.index);
            }else{
                system.error("失败!" + res.msg + "!");
            }
        }, function (res) {
            system.error("失败!" + res.msg + "!");
        });
        ajax.set("roleIds", ids);
        ajax.start();
        return false;
    });

    var setting = {
        check: {
            enable: true,
            chkboxType: {
                "Y": "ps",
                "N": "ps"
            }
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };

    var ztree = new $ZTree("zTree", "/admin/menuRole/search/tree/" + system.getUrlParam("id"));
    ztree.setSettings(setting);
    ztree.init();
});